package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter@Setter@ToString
public class StrategyComment extends BaseDomain {

    public static final Integer STATE_DISABLE =-1;
    public static final Integer STATE_COMMON =0;
    public static final Integer STATE_HOT =1;


    private User user;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;

    private String content;

    private String imgUrls;

    private Integer starNum;

    private Strategy strategy;

    private Integer state=STATE_COMMON;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date commendTime;


    public String[] getImgArr(){
        if (imgUrls != null) {
            String[] imgArr = imgUrls.split(";");
            return imgArr;
        }
        return  null;
    }

    public String getStateName(){
        String stateName="普通";
        if(STATE_HOT.equals(state)){
            stateName="热门";
        }else if(STATE_DISABLE.equals(state)){
            stateName="禁用";
        }
        return stateName;
    }

    public Object getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("user",user);
        map.put("content",content);
        map.put("imgUrls",imgUrls);
        map.put("starNum",starNum);
        map.put("strategy",strategy);
        map.put("state",state);
        return JSONUtil.toJSONString(map);
    }
}